package com.symbio.ishenapi.doctor.controller;

import com.symbio.ishenapi.common.bean.LoginUser;
import com.symbio.ishenapi.common.controller.BaseController;
import com.symbio.ishenapi.doctor.model.TmGroupMessageTemplate;
import io.jboot.web.controller.annotation.RequestMapping;

import java.util.List;

/**
 * @Author: chen
 * @Description:群管理模版控制层
 * @Date: Created in 16:07 2018/12/3
 * @Modified By:
 */
@RequestMapping("/TmGroupMessageTemplate")
public class TmGroupMessageTemplateController extends BaseController{

    /** POST
     * @Author: chen
     * @Description:保存群消息模版
     * @Date: 16:08 2018/12/3
     * @param: [
     *              "groupId":"群id",
     *              "content":"模版消息内容"
     *          ]
     * @return: void
     */
    public void save(){
        try {
            TmGroupMessageTemplate template = (TmGroupMessageTemplate)getReqBodyObject(TmGroupMessageTemplate.class);
            LoginUser loginUser = getLoginUser();
            TmGroupMessageTemplate.dao.saveTemplate(template,loginUser);
            renderJsonError(50001,"模版保存");
        }catch (Exception e){
            e.printStackTrace();
            renderJsonError(50002,"模版保存");
        }
    }

    /** GET
     * @Author: chen
     * @Description:根据分组id获取模版集合
     * @Date: 16:17 2018/12/3
     * @param: [
     *           groupId	---群id
     *          ]
     * @return: void
     */
    public void findTemplagesByGroupId(){
        try {
            String groupId = getPara("groupId");
            List<TmGroupMessageTemplate> data = TmGroupMessageTemplate.dao.findTemplagesByGroupId(groupId);
            renderJsonRet(data);
        }catch (Exception e){
            e.printStackTrace();
            renderJsonError(50002,"分组模版查询");
        }
    }

    /** 删除模版
     * @Author: 删除模版
     * @Description:
     * @Date: 17:54 2018/12/3
     * @param: [
     *              id	---模版唯一id
     *          ]
     * @return: void
     */
    public void delete(){
        try {
            String id = getPara("id");
            TmGroupMessageTemplate.dao.deleteTemplate(id);
            renderJsonError(50001,"模版删除");
        }catch (Exception e){
            e.printStackTrace();
            renderJsonError(50002,"模版删除");
        }
    }
}
